const App = getApp()
const WxParse = require('../../wxParse/wxParse.js');
const utils = require('../../utils/utils.js');
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
Component({
  data: {
    attr: {},
    price: {
      origin: 1,
      vip: 0.5,
      uprice:0.5
    },
  },
  properties: {
    sid:{
      type:Number,
      value:999
    }
  },
  attached: function () {
  }, // 此处attached的声明会被lifetimes字段中的声明覆盖

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () {
      var _this = this;
      App.globalData.serviceModel.detail({ data: { 'id': _this.properties.sid, }}).then(json => {
        _this.setData({ servicedata: json.data})
        WxParse.wxParse('content', 'html', json.data.content, _this, 5);
      })
    },
    hide: function () {},
    resize: function () {},
  },

  methods: {
    select: function (e) {
      var _this = this;
      var attr = _this.data.attr;
      var obj = e.target.dataset;
      attr[obj.spec] = obj.id;
      _this.setData({ attr: attr})
      this.triggerEvent('setD',_this.data);
      App.globalData.serviceModel.getPrice({
        data: { cids: Object.values(attr)}
      }).then(json => {
        var data = json.data;
        if (data) {
          _this.setData({
            price: {
              origin: data.price,
              vip: data.vip_price,
              uprice:data.uprice
            }
          })
        } else {
          Toast("当前组合不支持购买")
        }
      })
    },
  }
})